<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" />
<title>Lens correction model - PanoTools.org Wiki</title>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="generator" content="MediaWiki 1.23.6" />






<style media="screen" type="text/css" title="Screen style sheet"> @import url(manual.css); </style>

<style>a:lang(ar),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}
/* cache key: panotools_wiki:resourceloader:filter:minify-css:7:90730a7865ba4b50e0b837e1821ff0a3 */</style>



<!--[if lt IE 7]><style type="text/css">body{behavior:url("/skins/vector/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-Lens_correction_model skin-vector action-view vector-animateLayout">
		
		
		<div id="content" class="mw-body" role="main">
			<a id="top"></a>
			
						<h1 id="firstHeading" class="firstHeading" lang="en"><span dir="auto">Lens correction model</span></h1>
						<div id="bodyContent">
								<div id="siteSub">From PanoTools.org Wiki</div>
								
												
				<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><p><br />
</p>
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="Lens_correction_model.html#Lens_correction_model"><span class="tocnumber">1</span> <span class="toctext">Lens correction model</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="Lens_correction_model.html#Field_of_View"><span class="tocnumber">1.1</span> <span class="toctext">Field of View</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="Lens_correction_model.html#Lens_distortion_a.2C_b_.26_c_parameters"><span class="tocnumber">1.2</span> <span class="toctext">Lens distortion a, b &amp; c parameters</span></a>
<ul>
<li class="toclevel-3 tocsection-4"><a href="Lens_correction_model.html#Lens_distortion_and_fisheyes"><span class="tocnumber">1.2.1</span> <span class="toctext">Lens distortion and fisheyes</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-5"><a href="Lens_correction_model.html#Lens_or_image_shift_d_.26_e_parameters"><span class="tocnumber">1.3</span> <span class="toctext">Lens or image shift d &amp; e parameters</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="Lens_correction_model.html#Image_shear_g_.26_t_parameters"><span class="tocnumber">1.4</span> <span class="toctext">Image shear g &amp; t parameters</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="Lens_correction_model.html#Determine_lens_correction"><span class="tocnumber">1.5</span> <span class="toctext">Determine lens correction</span></a></li>
<li class="toclevel-2 tocsection-8"><a href="Lens_correction_model.html#Optimize_for_lens_correction"><span class="tocnumber">1.6</span> <span class="toctext">Optimize for lens correction</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="Lens_correction_model.html#Tools_to_correct_barrel_and_pincushion_distortion"><span class="tocnumber">1.7</span> <span class="toctext">Tools to correct barrel and pincushion distortion</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="Lens_correction_model.html#See_also"><span class="tocnumber">1.8</span> <span class="toctext">See also</span></a></li>
</ul>
</li>
</ul>
</div>

<h2><span class="mw-headline" id="Lens_correction_model">Lens correction model</span></h2>
<p>The panorama tools have a very flexible model to correct for typical geometrical lens errors. Even better, it can often even estimate the correction parameters directly from the images in a panorama.
</p><p>There are a total of 6 parameters that have to do with lens correction. 
</p>
<ul>
<li> First of all there is the lens <a href="Field_of_View.html" title="Field of View">Field of View</a> (FoV) - not exactly an error, but a parameter that determines the image perspective distortion. 
</li>
<li> The actual lens correction parameters <b>a</b>, <b>b</b> and <b>c</b> which are used to correct for <a href="Barrel_distortion.html" title="Barrel distortion">barrel distortion</a>, <a href="Pincushion_distortion.html" title="Pincushion distortion">pincushion distortion</a> and even <a href="Wavy_distortion.html" title="Wavy distortion">wavy distortion</a>.
</li>
<li> The lens shift parameters <b>d</b> and <b>e</b> that correct for the lens optical axis<a class="external" href="http://wiki.panotools.org/Optical_axis">[*]</a> not being in the image center.
</li>
</ul>
<p>Two more parameters correct for image errors that are not induced by the lens but by a scanner or scanning camera for example. These are the shear parameters <b>f</b> and <b>g</b>.
</p>
<h3><span class="mw-headline" id="Field_of_View">Field of View</span></h3>
<p>The <a href="Focal_Length.html" title="Focal Length">Focal Length</a> is a physical property of the lens. Together with the effective sensor or film size and the focusing distance it approximates the image <a href="Field_of_View.html" title="Field of View">Field of View</a> (there are other factors that influence it). <b>Caution</b>: Cropping the image changes the Field of View. If you need to crop your source images for a panorama, crop them all to the same size!
</p><p>The Field of View together with the lens projection (<a href="Rectilinear_Projection.html" title="Rectilinear Projection">rectilinear</a>, <a href="Fisheye_Projection.html" title="Fisheye Projection">fisheye</a> or <a href="Cylindrical_Projection.html" title="Cylindrical Projection">cylindrical</a> for swing lens cameras) determine the image <a href="Perspective_distortion.html" title="Perspective distortion">perspective distortion</a>. Perspective distortion is less with a smaller Field of View. See Helmut Dersch page <a rel="nofollow" class="external autonumber" href="http://www.panotools.org/dersch/perspective/Wide_Angle_Perspective.html">[1]</a> for details about different wide angle perspectives.
</p>
<h3><span class="mw-headline" id="Lens_distortion_a.2C_b_.26_c_parameters">Lens distortion a, b &amp; c parameters</span></h3>
<p>For perfect <a href="Rectilinear_Projection.html" title="Rectilinear Projection">rectilinear</a> camera optics, all you would need to know is the field of view.  Perfect results could be achieved by simply mapping pixels in the image to the tangent plane<a class="external" href="http://wiki.panotools.org/index.php?title=Tangent_plane&amp;action=edit&amp;redlink=1">[*]</a>.  Real lenses deviate from this perfect tangent plane projection.  The deviations push and pull fixed points in the scene away from where they would have fallen.  Luckily, rather than arbitrary pushes and pulls, almost all deviations occur radially, towards or away from some common center, and luckily the deviation amount is almost the same at a given radius around that center. Hence a model that corrects for this deviation based on the radius gives pretty good results.
</p><p>The <a href="Lens_distortion.html" title="Lens distortion">lens distortion</a> <b>a</b>, <b>b</b> and <b>c</b> parameters correspond to a third degree polynomial describing radial lens distortion: 
</p>
<dl>
<dd><img class="mwe-math-fallback-png-inline tex" alt="r_{{src}}=({a}r_{{dest}}^{3}+{b}r_{{dest}}^{2}+{c}r_{{dest}}+d)r_{{dest}}" src="d4466e5ff97cd6bbdddc514f3a28fb88.png" />
</dd>
</dl>
<p>where <img class="mwe-math-fallback-png-inline tex" alt="r_{{dest}}" src="a98f19317c5b1baf19a11563189c874b.png" /> and <img class="mwe-math-fallback-png-inline tex" alt="r_{{src}}" src="16788a4cd7337294823325c28db92225.png" /> refer to the normalized radius of an image pixel. The center point of this radius is where the optical axis<a class="external" href="http://wiki.panotools.org/Optical_axis">[*]</a> hits the image - normally the image center.  Normalized means here that the largest circle that completely fits into an image is said to have radius=1.0 .  (In other words, radius=1.0 is half the smaller side of the image.) A perfect lens would have <b>a</b>=<b>b</b>=<b>c</b>=0.0 and <b>d</b>=1.0 which resolves into  <img class="mwe-math-fallback-png-inline tex" alt="r_{{src}}=r_{{dest}}" src="f10801280c8b36520b1a628171f25d8f.png" />.
</p><p>Sometimes the above formula is written as 
</p>
<dl>
<dd><img class="mwe-math-fallback-png-inline tex" alt="r_{{src}}={a}r_{{dest}}^{4}+{b}r_{{dest}}^{3}+{c}r_{{dest}}^{2}+d{r_{{dest}}}" src="17af7474cdfd5abe24fd07eb58810dba.png" />
</dd>
</dl>
<p>which is essentially the same.
</p><p>Usual values for <b>a</b>, <b>b</b> and <b>c</b> are below 1.0, in most cases below 0.01. Too high values suggest that you chose a wrong lens type, f.e. fisheye instead of rectilinear or vice versa. This refers to the absolute values of course since <b>a</b>, <b>b</b> and <b>c</b> can be positive or negative (f.e. both 4.5 and -4.5 are considered too high values).
</p><p>The fourth parameter (<b>d</b>) is only available in the Correct, Radial Shift<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins#Radial_Shift">[*]</a> filter of the Panorama Tools Plugins<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins">[*]</a>. It is calculated implicitly by <a href="Pano12.html" title="Pano12">pano12</a> (used by PTOptimizer, PTStitcher and the GUIs) in order to keep the same image size: 
</p>
<dl>
<dd><img class="mwe-math-fallback-png-inline tex" alt="d=1-(a+b+c)" src="990bd2a1181cb4840ca9ff6b710ca7ec.png" />
</dd>
</dl>
<p>Hence it is not available in the different GUI front-ends<a class="external" href="http://wiki.panotools.org/GUI_front-ends">[*]</a> (you can see it in the PTOptimizer result script).
</p><p>Unfortunately a different parameter also named <b>d</b> refers to image shift in PTStitcher and PTOptimizer scripts and the GUIs.  This sometimes causes confusion. (See more discussion below.)
</p><p>This polynomial approach is never exact, but can give a pretty good approximation to the real behaviour of a given lens. If you need better correction you must use a distortion matrix, as used by <b>Distortion Remove</b> (see link below). 
</p>
<h4><span class="mw-headline" id="Lens_distortion_and_fisheyes">Lens distortion and fisheyes</span></h4>
<p>Unlike rectilinear lenses, fish-eye lenses do not follow the tangent-plane geometry, but instead have <i>built-in</i> distortions designed to achieve wide fields of view.  The radial lens distortion parameters are used the same way for rectilinear lenses and fisheye lenses<a class="external" href="http://wiki.panotools.org/Fisheyes">[*]</a>, but they should never be used to attempt to remap a fisheye to a rectilinear image.  This is done by selecting the proper source and destination projection.  Fisheye geometry follows a rapidly-changing trigonometric function which can hardly be approximated by a third degree polynomial.
</p><p>For fisheyes, the lens correction parameters correct for the deviation between a real lens and the <a href="Fisheye_Projection.html" title="Fisheye Projection">ideal fisheye geometry</a>.
</p>
<h3><span class="mw-headline" id="Lens_or_image_shift_d_.26_e_parameters">Lens or image shift d &amp; e parameters</span></h3>
<p>Sometimes a lens and image sensor might not be centered with respect to each other. In this case the optical axis<a class="external" href="http://wiki.panotools.org/Optical_axis">[*]</a> doesn't fall on the image center. This is particularly the case for scanned images where you never can say whether the film is centered on the scanner or not.
</p><p>If the above lens correction algorithm is used on such images both lens correction and perspective correction work on the wrong center point. The lens shift parameters <b>d</b> (horizontal shift) and <b>e</b> (vertical shift) compensate for that problem. They contain values in pixel units which determine how far the center for radial correction is shifted outside the geometrical image center.
</p>
<h3><span class="mw-headline" id="Image_shear_g_.26_t_parameters">Image shear g &amp; t parameters</span></h3>
<p>Image shear is not a <a href="Lens_distortion.html" title="Lens distortion">lens distortion</a> but nevertheless is part of the panotools lens correction model. It corrects for a distortion induced by scanners or scanning cameras that causes a rectangular image being sheared to the form of a parallelogram (one side of the images is shifted parallel to the opposite side)
</p>
<h3><span class="mw-headline" id="Determine_lens_correction">Determine lens correction</span></h3>
<p><b>a</b>, <b>b</b>, <b>c</b> and <b>FoV</b> are physical properties of a lens/camera-combination at a given focus distance. If you always shoot at the same focus setting, f.e. infinity or the <a href="Depth_of_Field.html#Hyperfocal_distance" title="Depth of Field">hyperfocal distance</a>, then you can safely reuse the parameters.  At different focus settings, <b>FoV</b> will change noticeably, but usually it is fine to reuse <b>a</b>, <b>b</b>, and <b>c</b> even then.
</p><p>There are a number of ways to determine the a, b, c and <a href="Field_of_View.html" title="Field of View">fov</a>
parameters to calibrate a particular lens/camera combination:
</p>
<ul>
<li> Taking a single photograph of a subject containing straight lines, defining one or more sets of <a href="Straight_line_control_points.html" title="Straight line control points">straight line control points</a> (types t3, t4, etc.), and optimising for just a, b, c.  You need to set the output format to <a href="Rectilinear_Projection.html" title="Rectilinear Projection">Rectilinear Projection</a> for this technique to work.  This method is used by the author of PTLens<a class="external" href="http://wiki.panotools.org/PTLens">[*]</a>.  The calibrate_lens<a class="external" href="http://wiki.panotools.org/index.php?title=Calibrate_lens&amp;action=edit&amp;redlink=1">[*]</a> tool also uses this technique and can operate with <a href="Fisheye_Projection.html" title="Fisheye Projection">Fisheye Projection</a> images greater than 180°.
</li>
</ul>
<ul>
<li> Taking a single photograph of a rectangular or grid object, selecting lots of <a href="Horizontal_control_points.html" title="Horizontal control points">horizontal</a> and <a href="Vertical_control_points.html" title="Vertical control points">vertical control points</a>, then optimising <a href="Roll.html" title="Roll">roll</a>, <a href="Pitch.html" title="Pitch">pitch</a>, <a href="Yaw.html" title="Yaw">yaw</a>, <a href="Field_of_View.html" title="Field of View">fov</a>, a, b &amp; c. You need to set the output format to <a href="Rectilinear_Projection.html" title="Rectilinear Projection">Rectilinear Projection</a> for this technique to work.  The process is similar to this <a rel="nofollow" class="external text" href="http://hugin.sourceforge.net/tutorials/architectural/">hugin architectural tutorial</a>:
</li>
</ul>
<ul>
<li> Taking two or more overlapping photographs and selecting lots of normal control points, then optimising <a href="Roll.html" title="Roll">roll</a>, <a href="Pitch.html" title="Pitch">pitch</a>, <a href="Yaw.html" title="Yaw">yaw</a>, <a href="Field_of_View.html" title="Field of View">fov</a>, a, b &amp; c. This technique works with any output <a href="Projections.html" title="Projections">projection format</a> but requires <a href="Parallax.html" title="Parallax">parallax</a> free images shot exactly from the <a href="Nodal_Point.html" title="Nodal Point">Nodal Point</a>. Note that to get a precise measure of the <a href="Field_of_View.html" title="Field of View">Field of View</a>, you have to take a full 360 degree panorama.
</li>
</ul>
<ul>
<li> Using points that are known to be directly above each other such as edges of buildings, windows, reflections in ponds etc... This is the <a href="Vertical_control_points.html" title="Vertical control points">vertical control points</a> method and works with <a href="Equirectangular_Projection.html" title="Equirectangular Projection">Equirectangular Projection</a> or <a href="Rectilinear_Projection.html" title="Rectilinear Projection">Rectilinear Projection</a> output and all lenses including those wider than 180°.
</li>
</ul>
<ul>
<li> Using a tool such as PTLens<a class="external" href="http://wiki.panotools.org/PTLens">[*]</a>, lensfun<a class="external" href="http://wiki.panotools.org/index.php?title=Lensfun&amp;action=edit&amp;redlink=1">[*]</a> or <a href="Fulla.html" title="Fulla">fulla</a> to read the photo <a href="EXIF.html" title="EXIF">EXIF</a> metadata and correct the image automatically by looking up the lens in an existing database.
</li>
</ul>
<h3><span class="mw-headline" id="Optimize_for_lens_correction">Optimize for lens correction</span></h3>
<p>If you optimize for lens correction in order to calibrate your lens you should keep some facts in mind: 
</p><p>Since lens correction parameters are determined by evaluating the distortion at different radius values you should provide enough control points at a large range of radii from the image center.
</p>
<ul>
<li> If you use a rectangular pattern or straight lines for that task, make sure you set control points in all distances from the center. 
</li>
<li> If you use two or more images make sure you overlap regions with large potential distortion (f.e. the corners) with regions with low possible distortion (f.e. the center). An only horizontal overlap would do, but use at least 50% in order to overlap the image center of one image with the border of the other.
</li>
</ul>
<p><b>a</b>, <b>b</b> and <b>c</b> parameters influence <a href="Field_of_View.html" title="Field of View">Field of View</a>, especially for images in landscape orientation but slightly for portrait oriented ones, too. This is because although the implicit calculation of the fourth polynomial parameter tries to keep the image at the same size, this is only possible at the radius <b>r_src</b> = 1.0. 
</p><p>Outside this radius, especially in the image corners, the size and hence the Field of View might differ. Since they are interconnected in this way, you should always allow the optimization for FoV too, if you optimize for <b>a</b>, <b>b</b> and <b>c</b> with more than one image. (You cannot optimize for FoV with only one image). As noted above you need a full 360 degree panorama in order to get an accurate measure of the <a href="Field_of_View.html" title="Field of View">Field of View</a>.
</p><p>The <b>a</b> and <b>c</b> parameters control more complex forms of distortion. In most cases it will be enough to optimize for the <b>b</b> parameter only, which is good at correcting normal <a href="Barrel_distortion.html" title="Barrel distortion">barrel distortion</a> and <a href="Pincushion_distortion.html" title="Pincushion distortion">pincushion distortion</a>.
</p><p>If you want to see how changing the parameters influences distortion correction go to <a rel="nofollow" class="external free" href="http://4pi.org/downloads/">http://4pi.org/downloads/</a> and get <b>abc.xls</b>. Don't deactivate macros on loading.
</p><p>See also <a rel="nofollow" class="external text" href="http://www.panotools.org/dersch/barrel/barrel.html">Helmut Dersch's barrel distortion page</a>.
</p><p>There's an excellent tutorial on how to optimize by John Houghton: <a rel="nofollow" class="external autonumber" href="http://johnhpanos.com/optitute.htm">[2]</a>
</p>
<h3><span class="mw-headline" id="Tools_to_correct_barrel_and_pincushion_distortion">Tools to correct barrel and pincushion distortion</span></h3>
<ul>
<li> The original <a href="PTStitcher.html" title="PTStitcher">PTStitcher</a> can be scripted to batch process images with known a, b &amp; c parameters.  It can also be operated with one of the GUI front-ends<a class="external" href="http://wiki.panotools.org/GUI_front-ends">[*]</a>.
</li>
</ul>
<ul>
<li> <a href="Nona.html" title="Nona">nona</a> (part of the <a href="Hugin.html" title="Hugin">hugin</a> distribution) can be used identically to <a href="PTStitcher.html" title="PTStitcher">PTStitcher</a>.
</li>
</ul>
<ul>
<li> The Correct Radial Shift<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins#Radial_Shift">[*]</a> filter in the Panorama Tools Plugins<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins">[*]</a> for the gimp<a class="external" href="http://wiki.panotools.org/Gimp">[*]</a> or photoshop<a class="external" href="http://wiki.panotools.org/Photoshop">[*]</a> uses the same a, b &amp; c parameters as <a href="PTStitcher.html" title="PTStitcher">PTStitcher</a>.  Note that it doesn't know about d &amp; e shift parameters and uses 'd' as an overall scaling factor instead, which should be d = 1-(a+b+c) to keep the image roughly the same size. If you need to shift the correction center like with the d &amp; e parameter you must combine it with Vertical Shift<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift">[*]</a> and/or Horizontal Shift<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift">[*]</a>.
</li>
</ul>
<ul>
<li> PTLens<a class="external" href="http://wiki.panotools.org/PTLens">[*]</a> is a Photoshop<a class="external" href="http://wiki.panotools.org/Photoshop">[*]</a> plugin and a stand-alone Windows tool that uses the same a, b &amp; c parameters and comes with a database of popular lenses.
</li>
</ul>
<ul>
<li> Clens<a class="external" href="http://wiki.panotools.org/Clens">[*]</a> is a command line version of PTLens<a class="external" href="http://wiki.panotools.org/PTLens">[*]</a>.
</li>
</ul>
<ul>
<li> <a href="Fulla.html" title="Fulla">fulla</a> is a command-line tool that uses the same a, b, c &amp; d parameters to correct <a href="Barrel_distortion.html" title="Barrel distortion">barrel distortion</a>.  It can also correct <a href="Chromatic_aberration.html" title="Chromatic aberration">chromatic aberration</a> and <a href="Vignetting.html" title="Vignetting">vignetting</a> at the same time.
</li>
</ul>
<ul>
<li> PTShift<a class="external" href="http://wiki.panotools.org/PTShift">[*]</a> determines different a, b &amp; c parameters for the three color channels in order to correct for <a href="Chromatic_aberration.html" title="Chromatic aberration">Chromatic aberration</a> with the Correct Radial Shift<a class="external" href="http://wiki.panotools.org/Panorama_Tools_Plugins#Radial_Shift">[*]</a> filter.
</li>
</ul>
<ul>
<li> Gimp wideangle plugin<a class="external" href="http://wiki.panotools.org/Gimp_wideangle_plugin">[*]</a> uses a different formula altogether to correct distortion.
</li>
</ul>
<ul>
<li> Gimp phfluuh plugin<a class="external" href="http://wiki.panotools.org/Gimp_phfluuh_plugin">[*]</a> is another tool that corrects lens distortion using yet another formula.
</li>
</ul>
<ul>
<li> CamChecker<a class="external" href="http://wiki.panotools.org/index.php?title=CamChecker&amp;action=edit&amp;redlink=1">[*]</a> is a tool for automatically determining lens distortion and generates a different set of parameters from everything else.
</li>
</ul>
<ul>
<li> zhang_undistort<a class="external" href="http://wiki.panotools.org/index.php?title=Zhang_undistort&amp;action=edit&amp;redlink=1">[*]</a> is a tool distributed with <a href="Hugin.html" title="Hugin">hugin</a> that uses CamChecker<a class="external" href="http://wiki.panotools.org/index.php?title=CamChecker&amp;action=edit&amp;redlink=1">[*]</a> parameters to actually correct distortion.
</li>
</ul>
<ul>
<li> Distortion Remove<a class="external" href="http://wiki.panotools.org/index.php?title=Distortion_Remove&amp;action=edit&amp;redlink=1">[*]</a> uses a completely different approach with a distortion matrix. Page in german only: <a rel="nofollow" class="external free" href="http://www.stoske.de/digicam/Artikel/verzeichnung.html">http://www.stoske.de/digicam/Artikel/verzeichnung.html</a>
</li>
</ul>
<h3><span class="mw-headline" id="See_also">See also</span></h3>
<p><a href="Image_positioning_model.html" title="Image positioning model">Image positioning model</a>
</p>



</div>								<div class="printfooter">
				Retrieved from "http://wiki.panotools.org/index.php?title=Lens_correction_model&amp;oldid=15559<a class="external" href="http://wiki.panotools.org/index.php?title=Lens_correction_model&amp;oldid=15559">[*]</a>"				</div>
												</div></div></body></html>